package services

import (
	"gin-app/app/common/request"
	"gin-app/app/models"
	"gin-app/global"
)

type chapterService struct {
}

var ChapterService = new(chapterService)

// 新建章节
func (n chapterService) CreateChapter(params request.CreateChapter) (err error, chapter *models.Chapter) {
	chapter = models.NewChapter(params.NovelID, params.Name, params.Content)
	err = global.App.DB.Create(chapter).Error
	return
}

// 获取章节列表
func (n chapterService) GetChapterList() (err error, chapter []models.Chapter) {
	err = global.App.DB.Find(&chapter).Error
	return
}

func (n chapterService) GetChapter(params request.GetChapterDetail) (err error, chapter []models.Chapter) {
	err = global.App.DB.Where("id = ?", params.ID).First(&chapter).Error
	return

}
